import os
import logging
from datetime import datetime
import numpy as np

from lib.data_class import brt_class
from uitls.get_data_info import _get_pattern_list_ini_info
# 配置日志记录

def _inital_log():
    if not os.path.exists('./log/'):
        os.mkdir('./log/')
    logging.basicConfig(filename='./log/'+datetime.today().strftime('%Y_%m_%d')+'.log',
                        level=logging.INFO,
                        format='%(asctime)s - %(levelname)s - %(message)s')
    # 实例化日志
    logger = logging.getLogger(__name__)
    return logger

def logger_tm(message):
    logger_ori = _inital_log()
    # log record in logger txt and commend
    logger_ori.info(message)
    print(message)

def _inital_brt(cfg):
    color, gray_level = _get_pattern_list_ini_info(cfg)
    datar = np.zeros([*(np.fromstring(cfg['Panel']['panel_res_r'], dtype=int, sep=',')),len(gray_level)])
    datag = np.zeros([*(np.fromstring(cfg['Panel']['panel_res_g'], dtype=int, sep=',')),len(gray_level)])
    datab = np.zeros([*(np.fromstring(cfg['Panel']['panel_res_b'], dtype=int, sep=',')),len(gray_level)])
    dataw = np.zeros([*(np.fromstring(cfg['Panel']['panel_res'], dtype=int, sep=',')),len(gray_level)])
    mapR = np.zeros([*datar.shape[0:2], 2])
    mapG = np.zeros([*datag.shape[0:2], 2])
    mapB = np.zeros([*datab.shape[0:2], 2])
    mapW = np.zeros([*dataw.shape[0:2], 2])

    brt = brt_class.BRT(datar,datag,datab,dataw,mapR,mapG,mapB,mapW,[],[],[],[],color,gray_level,[])
    print('brt inital')
    return brt

def _inital_brt_aoi(cfg):
    color, gray_level = _get_pattern_list_ini_info(cfg)
    datar = []
    datag = []
    datab = []
    dataw = []
    mapR = 0
    mapG = 0
    mapB = 0
    mapW = 0

    brt = brt_class.BRT(datar,datag,datab,dataw,mapR,mapG,mapB,mapW,[],[],[],[],color,gray_level,[])
    print('brt_aoi inital')
    return brt